<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>还本利息单新增</title>
</head>
<style>
	.fieldset{
		margin-top: 5px;
		margin-bottom: 0px
	}
	
	.layui-legend{
		background-color:#5fb878;
		font-size:15px !important;
		width:140px;
	}
	.layui-form-item {
	    margin-bottom: 5px;
	    clear: both;
	    *zoom: 1;
	}
	.layui-form-label{width:180px;} 
	.width108{
		width:80px;
	}

</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
	    <div class="layui-tab-item layui-show">
	    	<div style="padding-top:15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form">
				<fieldset class="layui-elem-field layui-field-title" style="margin-top: 16px;">
                 	<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;fontSize:100px;">申请信息></legend>
           		</fieldset>
				  <div style="margin-top:20px">
				  	<div class="layui-form-item">
						<div class="layui-inline">
					    	<label class="layui-form-label">融资业务名称</label>
				      		<div class="layui-input-inline">
					      		<select id="add_select_proId" name="codesAndproCode"  lay-filter="add_select_proId" lay-verify="required" lay-search>
					      			<option value="">请选择-融资业务名称</option>
				      				<c:if test="${not empty allProName }">
				              			<c:forEach items="${allProName}" var="proNames">
				              				<option value="${proNames.codes }_${proNames.proCode }_${proNames.proName }">${proNames.proName }_${proNames.codes }</option>
					            		</c:forEach>
				              		</c:if>
				      			</select>
				      		</div>
					    </div>
					    
					    <div class="layui-inline">
					   	 	<label class="layui-form-label">付款公司</label>
						   	 	<div class="layui-input-inline"id="query-select-pubIncome" lay-filter="query-select-pubIncome">
								</div>
						</div>
						
						 <div class="layui-inline">
						 <!-- 自动计算 -->
					   	 	<label class="layui-form-label">申请付款总额（元）</label>
					   	 	<div class="layui-input-inline">
				              	<input  value="0" style="border:0px"  readonly="readonly" class="layui-input"
									name="payTotal" id="payTotal"  />
								
							</div>
						</div>
					</div>
					<div style="margin-top:12px"></div>					
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					      	<label class="layui-form-label">申请公司</label>
					      	<div class="layui-input-inline">
								<input type="hidden" name="hrOrgid" value="${bindOrgId}">
								<input type="text" value="${bindOrgName}" style="border:0px;" readonly="readonly" class="layui-input">
					      	</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">申请部门</label>
				      		<div class="layui-input-inline">
				      			<input type="hidden" name="hrDeptid" value="${bindDeptId}">
								<input type="text" value="${bindDeptName}" style="border:0px;" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">申请人</label>
				      		<div class="layui-input-inline">
				        		<input type="hidden" name="hrStaffApplyid" value="${SESSION_KEY_USER_DETAIL.hrStaffId }">
				        		<input type="text" name="staffname" value="${staffName }" readonly="readonly" style="border:0px" autocomplete="off" class="layui-input">
				      		</div>
					    </div>
					</div>
					
					<div style="margin-top:12px"></div>	
			  		<div class="layui-form-item">
					    <div class="layui-inline">
					    	<label class="layui-form-label">申请付款日期</label>
					   		<div class="layui-input-inline">
				             	<div class="layui-input-inline">
				               		<input type="text"  class="layui-input" id="trackDate" name="applyPayDate" readOnly placeholder="申请付款日期" lay-verify="required">
				             	</div>
		       				</div>
		       			</div>
	       			 	<div class="layui-inline">
		       			 	 <label class="layui-form-label">结算方式</label>
		       			 	 <div class="layui-input-inline">
				             	<select  name="settlementMode"  lay-verify="required" lay-search>
					      			<option value="">请选择-结算方式</option>
				      				<option value="1">网银</option>
				      			</select>
		       				</div>
		       			 </div>
		       			 <div class="layui-inline">
		       			 	 <label class="layui-form-label">支出类型</label>
		       			 	 <div class="layui-input-inline">
				             	<select  name="payOutType"  lay-verify="required" lay-search>
					      			<option value="">请选择-支出类型</option>
				      				<option value="1">贷款</option>
				      				<option value="2">政府借款</option>
				      			</select>
		       				</div>
		       			 </div>
				    </div>
				    <div class="layui-form-item">
					    <div class="layui-inline">
					    	<label class="layui-form-label">摘要</label>
				      		<div class="layui-input-inline">
					      		<textarea name="summary" lay-verify="required" maxlength="500" placeholder="请输入摘要" class="layui-textarea" style="width:899px;height:90px;"></textarea>
				      		</div>
					    </div>
				    </div>
				<fieldset class="layui-elem-field layui-field-title" style="margin-top: 16px;">
                 	<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;fontSize:100px;">还款明细>></legend>
           		</fieldset>   
			  	<div style="margin-top:20px">
				  	<div class="layui-form-item"  >
					    <div class="layui-inline">
					    	<label class="layui-form-label" style="text-align:center;width:60px;">序号</label>
					    </div>
					    <div class="layui-inline">
					      	<label class="layui-form-label" style="text-align:left;width:160px;">还款对象单位</label>
					      	<!-- <div class="layui-input-inline">
					        	<input type="text" name="costMemo" value="" readonly="readonly" style="border:0px" class="layui-input">
					      	</div> -->
					    </div>
					    <div class="layui-inline">
					      	<label class="layui-form-label" style="text-align:left;width:160px;">还款类型</label>
					    </div>	
					    <div class="layui-inline">
					      	<label class="layui-form-label" style="text-align:left;width:150px;">开户银行名称</label>
					    </div>	
					    <div class="layui-inline">
					      	<label class="layui-form-label" style="text-align:left;width:90px;">银行账号</label>
					    </div>	
					    <div class="layui-inline">
					      	<label class="layui-form-label" style="text-align:center;width:110px;">还款金额（元）</label>
					      	<!-- <div class="layui-input-inline">
					        	<input type="text" name="costAmount" value="" readonly="readonly" style="border:0px" class="layui-input">
					      	</div> -->
					    </div>						    
				    </div>
				    
					<!-- 新增或删除的框 -->
				    <div style="margin-top:20px">  
				    <div class="layui-form-item" id="finCostRow1">
				    	<div class="layui-inline width108">
					    	<label class="layui-form-label" style="text-align:center;width:50px;">1</label>
					    	<div class="layui-input-inline">
					    		<input type="hidden" name="subWorkTargetShowIdx" value="1"/>
					    	</div>
					    </div>
					    <div class="layui-inline">
				      		<div class="layui-input-inline" style="margin-left:10px;width:175px;">
					      		<input type="text" name="accountName" placeholder="请输入" maxlength="50" autocomplete="off" lay-verify="required" class="layui-input">
				      		</div>
					    </div>
					    
					    <div class="layui-inline">
					      	<div class="layui-input-inline" style="margin-left:-10px;width:175px;">
					      		<select  name="payType"  lay-verify="required" lay-search>
									<option value="">请选择</option>
									<option value="1">归还本金</option>
									<option value="2">支付利息</option>
								</select>
					      	</div>
					    </div>
					    
					    <div class="layui-inline">
					      	<div class="layui-input-inline" style="margin-left:-10px;width:175px;">
					      		<input type="text" name="openBankName" placeholder="请输入" maxlength="100" autocomplete="off" lay-verify="required" class="layui-input">
					      	</div>
					    </div>
					    <div class="layui-inline">
					      	<div class="layui-input-inline" style="margin-left:-10px;width:175px;">
					      		<input type="text" name="accountNo"  placeholder="请输入" maxlength="19" autocomplete="off" lay-verify="required|bankcard" class="layui-input">
					      	</div>
					    </div>
					    
					    <div class="layui-inline">
					      	<div class="layui-input-inline" style="margin-left:-10px;width:100px;">
					      		<input type="text" name="paySingle" maxlength="13" onblur="checkMaxValue();arabiaToCN(this,1);" placeholder="请输入" autocomplete="off" lay-verify="required|floatAmount" class="layui-input">
					      	</div>
					    </div>
					    
					    <div class="layui-inline">
					    	<button type="button" class="layui-btn layui-btn-sm" id="addFinCostBtn1" onclick="addFinCostRow(this);"><i class="layui-icon">&#xe654;</i></button>
					    	<button type="button" class="layui-btn layui-btn-sm" style="display:none" id="delFinCostBtn1" onclick="delFinCostRow(1)"><i class="layui-icon">&#xe640;</i></button>
					    </div>
					    
				  </div>
				</div>
				
				<div class="layui-form-item">
			      	<label class="layui-form-label " style="width:150px">合计</label>
			      	<div class="layui-input-inline">
			        	<input type="text" name="" value="" readonly="readonly" style="border:1px" class="layui-input">
			      	</div>
			      	<div class="layui-input-inline" style="margin-left:490px;">
			        	<input type="text" id="heji" value="" style="border:0px"  readonly="readonly" class="layui-input">
			      	</div>
				</div>	
				<div class="layui-form-item">	
				 	<div class="layui-inline">
				    	<label class="layui-form-label" style="width:100px">备注</label>
			      		<div class="layui-input-inline">
				      		<textarea name="memo" maxlength="500" placeholder="请输入备注" class="layui-textarea" style="width:899px;height:90px;"></textarea>
			      		</div>
				    </div>
			    </div>
			</div>
				
			<fieldset class="layui-elem-field layui-field-title fieldset" >
			  		<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">附件信息  ></legend>
					  	<div style="margin-top:20px;">
						    <div class="layui-form-item">
							    <label class="layui-form-label" style="width:350px;">支持pdf、excel、word、图片资料，可上传多个</label>
							</div>
						    <div class="layui-form-item">
							    <label class="layui-form-label">贷款合同（选填）</label>
							    <div class="layui-input-block">
							    	<div class="layui-upload">
						              	<button type="button" class="layui-btn" id="1-upload-more">上传</button>
				                		<div class="layui-upload-list" id="1-upload-more-list">
				                		</div>
						            </div>
							    </div>
						  	</div>
						    <div class="layui-form-item">
							    <label class="layui-form-label">还本利息表（选填）</label>
							    <div class="layui-input-block">
							    	<div class="layui-upload">
						              	<button type="button" class="layui-btn" id="2-upload-more">上传</button>
				                		<div class="layui-upload-list" id="2-upload-more-list">
				                		</div>
						            </div>
							    </div>
						  	</div>
						    <div class="layui-form-item">
							    <label class="layui-form-label">其他资料（选填）</label>
							    <div class="layui-input-block">
							    	<div class="layui-upload">
						              	<button type="button" class="layui-btn" id="9-upload-more">上传</button>
				                		<div class="layui-upload-list" id="9-upload-more-list">
				                		</div>
						            </div>
							    </div>
						  	</div>
					  	</div>
				</fieldset>
            		
			</div> 
			  <div class="layui-form-item" style="position: fixed ! important; right: 30px; bottom:45%;z-index:10000;">
					<div class="layui-input-block">
			      		<button class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius" type="button" lay-submit lay-filter="addInfo_form_submit" id="addInfo_form_submit">
			      		<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i>
			      		提交
			      		</button>
			      	</div>
		      </div>			
		</form>
  		</div>
	</div>
</div>
  <script>
//静态资源路径前缀
	var staticPath = '${fileHttpPre}';
	var stateJSON = <infopub:dicJson groupNo="A00010028" />;
	
  layui.config({
    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set', 'upload', 'element', 'laydate'], function(){
    var $ = layui.$
    ,form = layui.form
    ,element = layui.element
    ,laydate = layui.laydate
    ,upload = layui.upload;
    
 	// 正则校验
	form.verify({
		//验证汉字
	    CHS:[
	    	/^[\u0391-\uFFE5]+$/
	    	,'只能输入汉字'
	  	],
	  	//大于0的正整数
	  	intNumber:[
			/^[1-9]\d*$/
			,'请输入正确的数字'
	  	],
	  	//数字只能有两位小数
	  	floatNumber:[
			/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			,'请输入正确的数字'
	  	],
	  	//数字大于等于0，并只能有两位小数
	  	floatAmount:[
			/^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
			,'请输入正确的数字'
	  	]
	});
 	
	//项目可研报告
  	upload.render({
	      elem: '#1-upload-more'
	      ,url: basePath + '/rpiApply/uploadAtt/' 
	      ,data: {
	    	  types:1
	    		}
	      ,multiple: true
	      ,accept: 'file'
	      ,acceptMime: 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf'
	   	  ,before: function(obj){ //obj参数包含的信息
	   		    layer.load(); //上传loading
	   		  }
	      ,done: function(res){
	    	  //如果上传失败
	          if(res.code > 0){
	        	  layer.closeAll('loading'); //关闭loading
	        	  return layer.msg(res.msg,{icon: 7});
	          }
	          //上传完毕
	   	  	  if(res.entity != null && res.entity.length > 0){
				for(var i in res.entity){
					var payfeeApply = res.entity[i];
					var arr = payfeeApply.split("|");
					var imgSrc = "";
					var suffix = arr[1].substring(arr[1].lastIndexOf(".")+1,arr[1].length);
					if(suffix == 'jpg' || suffix == 'png'){
						imgSrc = "${fileHttpPre}/"+arr[3];
					}else{
						imgSrc = "${ctx}/resources/images/"+suffix+".jpg";
					}
	        		$('#1-upload-more-list').append('<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'"><img src="'+imgSrc+'" title="'+ arr[1] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''+"${fileHttpPre}"+arr[3] +'\');">查看</a><a href="javascript:void(0)" onclick="del(\''+arr[2]+'\')";>删除</a></div><p>'+arr[1]+'</p><input type="hidden" value="'+payfeeApply+'" id="fileAtt_'+arr[2]+'" name="fileAtt1" ></input></div> ');
				}
		  	  }
	      }
	      ,allDone: function(obj){ //当文件全部被提交后，才触发
	    	  layer.closeAll('loading'); //关闭loading
	      }
	      ,error: function(){
	    	  layer.closeAll('loading'); //关闭loading
	          //上传失败
	          layer.msg("上传失败，请稍后再试~",{icon: 7});
	        }
	    });
	
  	upload.render({
	      elem: '#2-upload-more'
	      ,url: basePath + '/rpiApply/uploadAtt/'
	      ,data: {
	    	  types:2
	    		}
	      ,multiple: true
	      ,accept: 'file'
	      ,acceptMime: 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf'
	   	  ,before: function(obj){ //obj参数包含的信息
	   		    layer.load(); //上传loading
	   		  }
	      ,done: function(res){
	    	  //如果上传失败
	          if(res.code > 0){
	        	  layer.closeAll('loading'); //关闭loading
	        	  return layer.msg(res.msg,{icon: 7});
	          }
	          //上传完毕
	   	  	  if(res.entity != null && res.entity.length > 0){
				for(var i in res.entity){
					var fileAtt = res.entity[i];
					var arr = fileAtt.split("|");
					var imgSrc = "";
					var suffix = arr[1].substring(arr[1].lastIndexOf(".")+1,arr[1].length);
					if(suffix == 'jpg' || suffix == 'png'){
						imgSrc = "${fileHttpPre}/"+arr[3];
					}else{
						imgSrc = "${ctx}/resources/images/"+suffix+".jpg";
					}
	        		$('#2-upload-more-list').append('<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'"><img src="'+imgSrc+'" title="'+ arr[1] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''+"${fileHttpPre}"+arr[3] +'\');">查看</a><a href="javascript:void(0)" onclick="del(\''+arr[2]+'\')";>删除</a></div><p>'+arr[1]+'</p><input type="hidden" value="'+fileAtt+'" id="fileAtt_'+arr[2]+'" name="fileAtt2" ></input></div> ');
				}
		  	  }
	      }
	      ,allDone: function(obj){ //当文件全部被提交后，才触发
	    	  layer.closeAll('loading'); //关闭loading
	      }
	      ,error: function(){
	    	  layer.closeAll('loading'); //关闭loading
	          //上传失败
	          layer.msg("上传失败，请稍后再试~",{icon: 7});
	        }
	    });
	
  	upload.render({
	      elem: '#9-upload-more'
	      ,url: basePath + '/rpiApply/uploadAtt/'
	      ,data: {
	    	  types:9
	    		}
	      ,multiple: true
	      ,accept: 'file'
	      ,acceptMime: 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf'
	   	  ,before: function(obj){ //obj参数包含的信息
	   		    layer.load(); //上传loading
	   		  }
	      ,done: function(res){
	    	  //如果上传失败
	          if(res.code > 0){
	        	  layer.closeAll('loading'); //关闭loading
	        	  return layer.msg(res.msg,{icon: 7});
	          }
	          //上传完毕
	   	  	  if(res.entity != null && res.entity.length > 0){
				for(var i in res.entity){
					var fileAtt = res.entity[i];
					var arr = fileAtt.split("|");
					var imgSrc = "";
					var suffix = arr[1].substring(arr[1].lastIndexOf(".")+1,arr[1].length);
					if(suffix == 'jpg' || suffix == 'png'){
						imgSrc = "${fileHttpPre}/"+arr[3];
					}else{
						imgSrc = "${ctx}/resources/images/"+suffix+".jpg";
					}
	        		$('#9-upload-more-list').append('<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'"><img src="'+imgSrc+'" title="'+ arr[1] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''+"${fileHttpPre}"+arr[3] +'\');">查看</a><a href="javascript:void(0)" onclick="del(\''+arr[2]+'\')";>删除</a></div><p>'+arr[1]+'</p><input type="hidden" value="'+fileAtt+'" id="fileAtt_'+arr[2]+'" name="fileAtt9" ></input></div> ');
				}
		  	  }
	      }
	      ,allDone: function(obj){ //当文件全部被提交后，才触发
	    	  layer.closeAll('loading'); //关闭loading
	      }
	      ,error: function(){
	    	  layer.closeAll('loading'); //关闭loading
	          //上传失败
	          layer.msg("上传失败，请稍后再试~",{icon: 7});
	        }
	    });
	
 
	//费用期间
    laydate.render({
      elem: '#trackDate'
      ,type: 'date'
      ,format:'yyyy-MM-dd'
    });
	
	
	//融资业务名称select下拉监听
    form.on('select(add_select_proId)', function(data){
    	var codeAndId = data.value;
    	$('#query-select-pubIncome').html('');  //把id为query-select-proId的标签的值改为' '
    	if(codeAndId==''||codeAndId==null){
    		layer.msg('请选择融资业务名称',{icon: 0});
    		return;
    	}else{
    		getProPlotProId(codeAndId);  
    	}  	  	
    }); 
   	//监听提交
  	form.on('submit(addInfo_form_submit)', function(data){
  		$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
  		layer.load();
       	//提交 Ajax 成功后，静态更新表格中的数据
       	$.ajax({
           	type : 'post',
			url : basePath + '/rpiApply/save',
           	data: $('#addInfo_form').serialize(),
			success:function(result){
				if(result.success){
					layer.closeAll('loading'); //关闭loading
					layer.msg('提交单据成功~',{icon: 1});
					//两秒后关闭当前页面
					setTimeout(function(){
						/**
						 * 查找父菜单，并刷新
						 */
						var topDoc = $(window.top.document);
						var path = basePath + '/rpiApply/list';
						// 获取页面名称
						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
						if(name == '' || name == null){
							name = '融资还本付息单';
						}
						window.parent.layui.index.openTabsPage(path, name);
						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
						iframe[0].contentWindow.location.reload(true);
						
						/**
						 * 关闭当前页
						 */
						var currPath = basePath + '/rpiApply/add';
						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
				        }, 2000);
				}else{
					layer.closeAll('loading'); //关闭loading
  					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
					layer.msg(result.msg,{icon: 7});
			  	}
			}
       	});
   	});  
 	// data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  	
  });
  var reg = /^([1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;
  //通过下拉选择的融资业务名称不同显示不同的付款公司
	  function getProPlotProId(codesAndproCode){
		var $ = layui.$
	  	,form = layui.form
			$.ajax({
				type : "POST", //提交方式  
				url : "${ctx}/rpiApply/getOrgInfoAllByProCode",//付款公司信息
				data : {
					"codesAndproCode" :codesAndproCode
				},//数据，这里使用的是Json格式进行传输  
				success : function(result) {//返回数据根据结果进行相应的处理 
					if(result.flag==true){
						var strBuffer = "";
						var strBuffer2 = "";
						var orgInfo = result.orgInfo;
						strBuffer+= '<input type="hidden" name="hrOrgBillId"  value='+orgInfo.id ;
						strBuffer+= ' />';
						strBuffer2+= '<input readOnly="readOnly" type="text" value='+orgInfo.compName +' style="border:0px;font-size:15px;margin-top:8px; " />';
						$('#query-select-pubIncome').append(strBuffer);//这里给项目编号加strBuffer
						$('#query-select-pubIncome').append(strBuffer2);
						form.render();
					}else{
						layer.msg('数据通信异常~',{icon: 0});
					}
				} 
			});
	  }
	  
	//新增付费明细一行
		function addFinCostRow(t){
			var $ = layui.$;
			var delBtnCount = $("button[id^='delFinCostBtn']").length;
			if(delBtnCount == 1){
				$("button[id^='delFinCostBtn']").each(function(){
					$(this).removeAttr("style");
				});
			}
			var thisid = $(t).attr("id").substring(13);
			thisid = $("div[id=finCostRow" + thisid + "]").find("div:first").find("label").html();
			thisid = parseInt(thisid);
			var nextIndex = parseInt(thisid) + 1;
			var maxInd = $("div[id^='finCostRow']").length;
			$("div[id^='finCostRow']").each(function(){
				var tId = $(this).attr("id").substring(10);
				tId = parseInt(tId);
			  	if(tId > maxInd){
			  		maxInd = parseInt(tId);
			  	}
			  	var thisIndex = $(this).find("div:first").find("label").html();
			  	thisIndex = parseInt(thisIndex);
			  	var nextId = thisIndex + 1;
			  	if(thisIndex > thisid) {
			  		$("div[id=finCostRow" + tId + "]").find("div:first").find("label").html(nextId);
			  	}
			});
			var ind = maxInd + 1;		
			var medalHtml = '';
			medalHtml += '<div class=layui-form-item id="finCostRow'+ind+'">';
			medalHtml += '	<div class="layui-inline width108">';
			medalHtml += '	<label class="layui-form-label" style="text-align:center;width:50px;">'+nextIndex+'</label>';
			medalHtml += '		<div class="layui-input-inline">';
			medalHtml += '			<input type="hidden" name="subFinCostShowIdx" value="'+nextIndex+'"/>';	
			medalHtml += '		</div>';	
			medalHtml += '	</div>';			
			medalHtml += '	<div class="layui-inline">';	
			medalHtml += '		<div class="layui-input-inline" style="margin-left:10px;width:175px;">';	
			medalHtml += '			<input type="text" name="accountName" placeholder="请输入" maxlength="50" autocomplete="off" lay-verify="required" class="layui-input">';	
			medalHtml += '		</div>';	
			medalHtml += '	</div>';		
			medalHtml += '	<div class="layui-inline">';	
			medalHtml += '		<div class="layui-input-inline" style="margin-left:-10px;width:175px;">';	
			medalHtml += '			<select  name="payType"  lay-verify="required" lay-search>';
			medalHtml += '				<option value="">请选择</option>';
			medalHtml += '				<option value="1">归还本金</option>';
			medalHtml += '				<option value="2">支付利息</option>';
			medalHtml += '			</select>';
			medalHtml += '		</div>';	
			medalHtml += '	</div>';
			medalHtml += '	<div class="layui-inline">';	
			medalHtml += '		<div class="layui-input-inline" style="margin-left:-10px;width:175px;">';	
			medalHtml += '			<input type="text" name="openBankName" placeholder="请输入" maxlength="100" autocomplete="off" lay-verify="required" class="layui-input">';	
			medalHtml += '		</div>';	
			medalHtml += '	</div>';
			medalHtml += '	<div class="layui-inline">';	
			medalHtml += '		<div class="layui-input-inline" style="margin-left:-10px;width:175px;">';	
			medalHtml += '			<input type="text" name="accountNo" placeholder="请输入" maxlength="19" autocomplete="off" lay-verify="required|bankcard" class="layui-input">';	
			medalHtml += '		</div>';	
			medalHtml += '	</div>';
			medalHtml += '	<div class="layui-inline">';	
			medalHtml += '		<div class="layui-input-inline" style="margin-left:-10px;width:100px;">';	
			medalHtml += '			<input type="text"  name="paySingle" placeholder="请输入" name="paySingle" autocomplete="off"  onblur="checkMaxValue();arabiaToCN(this,1);" maxlength="13" lay-verify="required|floatAmount" class="layui-input">';	
			medalHtml += '		</div>';	
			medalHtml += '	</div>';
			medalHtml += '	<div class="layui-inline">';
			medalHtml += '		<button type="button" class="layui-btn layui-btn-sm" id="addFinCostBtn'+ind+'" onclick="addFinCostRow(this);"><i class="layui-icon">&#xe654;</i></button>';
			medalHtml += '		<button type="button" class="layui-btn layui-btn-sm" id="delFinCostBtn'+ind+'" onclick="delFinCostRow('+ind+')"><i class="layui-icon">&#xe640;</i></button>';
			medalHtml += '		</div>';	
			medalHtml += '	</div>';
			$(t).parent().parent().after(medalHtml);
			layui.form.render();
		}
		
		//删除付费明细一行
		function delFinCostRow(id){
			var $ = layui.$;
			layui.layer.confirm('确定删除？',{icon:3, title :'提示'}, function(index){
				
				var thisid = $("div[id=finCostRow" + id + "]").find("div:first").find("label").html();
		    	thisid = parseInt(thisid);
		    	$("div[id^='finCostRow']").each(function(){
					var tId = $(this).attr("id").substring(10);
					tId = parseInt(tId);
				  	var thisIndex = $("div[id=finCostRow" + tId + "]").find("div:first").find("label").html();
				  	thisIndex = parseInt(thisIndex);
				  	var nextId = thisIndex - 1;
				  	if(thisIndex > thisid) {
				  		$("div[id=finCostRow" + tId + "]").find("div:first").find("label").html(nextId);
				  	}
				});
		    			    	
				var strLoanAmount = $("div[id=finCostRow" + id + "]").find("input[name='paySingle']").val();  
				if(strLoanAmount==''||strLoanAmount==null||isNaN(strLoanAmount)){
					strLoanAmount=0
				}
				var totalCostStr = $('#heji').val();
				var totalCostNewStr = parseFloat(totalCostStr).toFixed(2)-parseFloat(strLoanAmount).toFixed(2);
				totalCostNewStr = parseFloat(totalCostNewStr).toFixed(2);
				
				if(totalCostNewStr==''||totalCostNewStr==null||isNaN(totalCostNewStr)){
					$('#heji').val(0);
					$('#payTotal').val(0);
				}else{
					$('#payTotal').val(totalCostNewStr); 
			  		$("#heji").val(totalCostNewStr);
				}		  		
		  		$("#finCostRow"+id).remove();
		  		var delBtnCount = $("button[id^='delFinCostBtn']").length;
				if(delBtnCount == 1){
					$("button[id^='delFinCostBtn']").each(function(){
						$(this).attr("style","display:none");
					});
				}
				layui.layer.close(index);
				
	 		});
		}
		
		//删除文件
		function del(index){
			layui.$("#fileAtt_"+index).remove();
			layui.$("#upload_img_"+index).remove();
		}
		 //根据url查看文件
		function showImg(url){
			var openWin = window.open(url,'','left=410,height=768, width=1024, top=200,  toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
		}
		 
		//计算合计
		function checkMaxValue(){
			var $ = layui.$;
			var sum = 0;
			$("input[name='paySingle']").each(function(){
				var num = $(this).val();
				if($(this).val()== '' ||$(this).val()== null||!reg.test($(this).val())){
					$(this).val(0);
					layer.msg('请输入正确数字，且保留两位小数！');
		  		}else{
		  			var thisVal = parseFloat($(this).val()).toFixed(2);
		  			sum = parseFloat(sum)+ parseFloat($(this).val());
		  			sum = parseFloat(sum).toFixed(2);					//转化为保留小数点后两位的数字
			  		$("#payTotal").val(sum);
			  		$("#heji").val(sum);
			  		var totalCost = $('#heji').val();
					if(totalCost==''||totalCost==null){
						$('#heji').val(0);
						$("#payTotal").val(0);
					}		  			
		  		}				
			});
		}
	 	
  </script>
</body>
</html>